<?php
namespace app\common\logic\home;

use app\common\model\VersionModel;
use app\common\model\UserVersionModel;

class version
{
	/**
	 * [版本检测]
	 * @param [type]  uuid  [description]
	 * @return [type] type [1 安卓 2 ios]
	 * @return [type] wgtVer [版本信息]
	 * @return [type] [description]
	 */
	public function index($param){
		$data = VersionModel::where('type',$param['type'])->order('version_id desc')->find();
		//如果是最新版本
		if ($param['wgtVer'] >= $data['number']) {
				return [
						'code'=>1,
						'msg'=>'不用更新',
					];
		}
		//如果不是最新版本
		else{
			//如果高于基本版本 不强制更新
			if($param['wgtVer'] >= $data['base_number']){
				$date = date('Y-m-d');
				$count = UserVersionModel::where('create_time',$date)->where('uuid',$param['uuid'])->count();
				//到达每日更新提示上线
				if($count >= $data['time']){
					return [
						'code'=>2,
						'msg'=>'不用提示更新',
						'data'=>$data,
					];
				}else{
					return [
						'code'=>-2,
						'msg'=>'提示更新',
						'data'=>$data,
					];
				}
			}
			//否则 强制更新
			else{
				return [
						'code'=>-1,
						'msg'=>'强制更新',
						'data'=>$data,
					];
			}
		}
	}
	/**
	 * [增加拒绝次数]
	 * @param [type]  uuid  [description]
	 */
	public function add($param){
		$UserVersion = new UserVersionModel();
		return $UserVersion->save($param);
	}
}
